﻿using AnesSystem.Models;
using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace AnesSystem.Converters
{
    class AccountId2Role : IValueConverter
    {
        
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                if (value == null) return "";
                if ("000000000000000000000000".Equals(value.ToString())) return "";
                if (value.ToString().Length == 24)
                {
                    AccountModel account = AccountListCtrlViewModel.Instance.AccountList.Find(O => O.Id.Equals(new MongoDB.Bson.ObjectId(value.ToString())));
                    return account.Title;
                }
                else
                {
                    return value;
                }
            }
            catch (Exception ex)
            {
                Common.LogHelper.Error(this.GetType(), ex);
                return value;

            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            
            return null;
        }
    }
}
